package com.tianzeculture.stagebao.activity.business;

import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.TextView;

import com.tianzeculture.stagebao.R;
import com.tianzeculture.stagebao.base.BaseActivity;
import com.tianzeculture.stagebao.network.enity.MSG;
import com.tianzeculture.stagebao.util.StatusBarUtil;
import com.tianzeculture.stagebao.util.Util;
import com.zhy.view.flowlayout.FlowLayout;
import com.zhy.view.flowlayout.TagAdapter;
import com.zhy.view.flowlayout.TagFlowLayout;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Created by Administrator on 2018/7/26 0026.
 * 工作标签
 */

public class WorkTagActivity extends BaseActivity {
    @BindView(R.id.tvTitle)
    TextView tvTitle;
    @BindView(R.id.btnSure)
    Button btnSure;


    @BindView(R.id.tagItems)
    TagFlowLayout tagItems;

    @Override
    public void initUI() {
        super.initUI();
        StatusBarUtil.setWindowStatusBarColor(this, R.color.colorGray_F8);
        tvTitle.setText("工作标签");

        initTag();
    }

    @OnClick(R.id.btnSure)
    public void saveTag() {
        Intent intent = new Intent();
        intent.putExtra("tagType",-1);
        intent.putStringArrayListExtra("checkTag", (ArrayList<String>) checkTags);
        setResult(Util.HOT_TAG,intent);
        finish();
    }

    List<String> tags = new ArrayList<>();
    List<String> checkTags = new ArrayList<>();

    private void initTag() {
        tags.clear();
        tags.add("时尚人像");
        tags.add("时装拍摄");
        tags.add("婚纱样片");
        tags.add("汽车广告");
        tags.add("泳装拍摄");
        tags.add("内衣拍摄");
        tags.add("个护化妆");
        tags.add("珠宝配饰");
        tags.add("游戏动漫");
        tags.add("数码产品");
        tags.add("家具用品");
        tags.add("其他用品");

        TagAdapter adapter = new TagAdapter(tags) {
            @Override
            public View getView(FlowLayout parent, final int position, Object o) {
                View view = LayoutInflater.from(WorkTagActivity.this).inflate(R.layout.item_work_tag, null);
                final CheckBox checkBox = view.findViewById(R.id.boxWorkTag);
                checkBox.setText(tags.get(position));

                checkBox.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        if (checkBox.isChecked()) {
                            checkTags.add(tags.get(position));
                        } else {
                            checkTags.remove(tags.get(position));
                        }
                    }
                });
                return view;
            }
        };
        tagItems.setMaxSelectCount(4);
        tagItems.setAdapter(adapter);
    }

    @Override
    public void refreshUI(int taskId, MSG msg) {
        super.refreshUI(taskId, msg);
    }

    @Override
    protected int getLayoutResID() {
        return R.layout.activity_work_tag;
    }
}
